<script setup lang="ts">
  useHead({
    titleTemplate: `%s | 请求测试2`,
    meta: [
      {
        name: "description",
        content: "请求测试页面2"
      }
    ]
  })

  import { getUserList, getUserByName, getUserByID } from "~/api/user"
  const list = ref<any>([])

  const getData = async () => {
    // 测试get请求带参数
  //   const res = await useFetch("/dev/users/one", {
  //     query: {
  //       name: 'Tom'
  //     }
  //   })

  // 测试post 请求带参数
    // const res = await useFetch("/dev/users/one", {
    //   method: "post",
    //   body: {
    //     id: 2
    //   }
    // })

    // const res = await fetchData("/users/list")
    // const res = await fetchGet("/users/list");
    // const res = await fetchGet("/users/one", {name: "Tom"});
    // const res = await fetchPost("/users/one", {id: 1});

    // const res = await getUserList();
    // const res = await getUserByName({ name: "Tom" })
    // const res = await getUserByID({ id: 1 })

    // const res = await fetchData("/users/test1")
    // const res = await fetchData("/users/test2")
    // const res = await fetchData("/users/test3")
    // const res = await fetchData("/users/test4")
    // const res = await fetchData("/users/test5")
    // const res = await fetchData("/users/test6")
    // const res = await fetchData("/users/refresh")
    // const res = await fetchData("/users/error")
    // console.log(111, res)

    const res = await fetchGet("/shopcart/list")
    if(res.result === 0){
      list.value = res.data
    }
  }

  await getData();
</script>

<template>
    <div>
         请求测试
         <u-button @click="getData" >发送请求</u-button>
         <ul v-if="list?.length > 0">
          <li v-for="item in list">{{ item }}</li>
         </ul>
    </div>
</template>

<style scoped>

</style>